package com.rimi.project.service.impl;

import com.rimi.project.bean.User;
import com.rimi.project.mapper.UserMapper;
import com.rimi.project.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * @author chao
 * @date 2020/2/21
 */

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    UserMapper userMapper;

    @Override
    public List<User> findAllUser() {
        return userMapper.findAll();
    }

    @Override
    public boolean login(User user) {

        if(Objects.isNull(user) || Objects.isNull(user.getUsername()) || Objects.isNull(user.getPassword())) {
            return false;
        }
        User userByUsernameAndPassword = userMapper.findUserByUsernameAndPassword(user);

        if(Objects.isNull(userByUsernameAndPassword)) {
            return false;
        }
        else {
            return true;
        }

    }
}
